﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NEWSPAPERINFOMATION
{

    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }
        DataTable dt = new DataTable();
        int Noposition = 0;
        String id;
        String passwd;

        private void Login_Load(object sender, EventArgs e)
        {
            
        }

        private void button_login_Click(object sender, EventArgs e)
        {
            if (checkuser.Checked)
            {
               
                string sql = "select * from users.Custom";
                BookConnection db = new BookConnection();
                dt = db.runSql(sql);
                if (dt.Rows.Count > 0)
                {
                    for (Noposition = 0; Noposition < dt.Rows.Count; Noposition++)
                    {
                        id = dt.Rows[Noposition]["customid"].ToString();
                        passwd = dt.Rows[Noposition]["passwd"].ToString();
                        if (id.Equals(userid.Text) && passwd.Equals(userpasswd.Text))
                        {
                            MessageBox.Show("登录成功");
                            new mainw("user", id).Show();
                          //  new From1("user",id).Show();    //有参构造，传入登录用户的类别以及id
                            return;
                        }

                    }
                    MessageBox.Show("密码错误，请重试");
                }
            }
            else if (checkadmin.Checked)
            {

                string sql = "select * from system.Manager";
                BookConnection db = new BookConnection();
                dt = db.runSql(sql);
                if (dt.Rows.Count > 0)
                {
                    for (Noposition = 0; Noposition < dt.Rows.Count; Noposition++)
                    {
                        id = dt.Rows[Noposition]["managerid"].ToString();
                        passwd = dt.Rows[Noposition]["passwd"].ToString();
                        if (id.Equals(userid.Text) && passwd.Equals(userpasswd.Text))
                        {
                            MessageBox.Show("登录成功");
                            
                            new mainw("admin", id).Show();    //有参构造，传入登录用户的类别以及id
                            return;
                        }

                    }
                    MessageBox.Show("密码错误，请重试");
                }
            }
            else
            {
                MessageBox.Show("请先选择登陆类型哦！");
            }
        }

        private void button_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void register_Click(object sender, EventArgs e)
        {
            new 用户注册().Show();
        }

      
    }
}
